package com.nulldev.util.net.packets.p2pc;

import com.nulldev.util.crypto.api2.EncryptionUtil;
import com.nulldev.util.crypto.api2.EncryptionUtil.Types;
import com.nulldev.util.crypto.encryptAPI.manage.EncryptAPI;
import com.nulldev.util.net.packets.APILevel;
import com.nulldev.util.net.packets.NetInfo;
import com.nulldev.util.net.packets.UniversalPacket;

@APILevel(level = 1)
@Deprecated
/**
 * Replaced by nCrypt API in nullUtil 2.6
 * @since nullUtil 2.0 / nPacket 1.0
 * @author null
 *
 */
public class P2PCKey extends UniversalPacket{

	public P2PCKey() {
		super("p2pC: Apply Key", "p2pc.setKey", "null");
	}

	@Override
	public void client(byte[] data, byte[] raw, final NetInfo client) {
		try {
			final String dkey = client.aformat();
			final String key = EncryptAPI.getEncryptorByID("encryptAPI.XXTEA").decrypt(createString(data), dkey); //EncryptionUtil.byType(Types.P2PE2_COMPRESS).decrypt(data, dkey);
			client.setKey(key);
		}catch (Exception e) {
			e.printStackTrace();
			return;
		}
	}

	@Override
	public void server(byte[] data, byte[] raw, final NetInfo connection) {
	}

}
